package ${location};

import org.apache.commons.lang3.StringUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import static ${location}.common.Constant.*;

/**
 * @author ${author}
 */
@SpringBootApplication
@EnableTransactionManagement
@MapperScan(basePackages = "${location}.mapper")
public class MainApplication {
	public static void main(String[] args) {
		ConfigurableApplicationContext ctx = SpringApplication.run(MainApplication.class, args);
		Environment env = ctx.getBean(Environment.class);
		String contextPath = LOCALHOST + (StringUtils.isBlank(env.getProperty(SERVER_PORT)) ? PORT_8080
				: env.getProperty(SERVER_PORT)) + (StringUtils.isBlank(env.getProperty(CONTEXT_PATH))
				? EMPTY : env.getProperty(CONTEXT_PATH));
		System.out.println("\n------------------------------------------------");
		System.out.println("项目路径:");
		System.out.println(contextPath);
		if (Boolean.TRUE.equals(env.getProperty(SWAGGER_SWITCH_ENABLE, boolean.class))) {
			System.out.println("API文档地址:");
			System.out.println(contextPath + (contextPath.endsWith(LEFT_SLASH) ? EMPTY : LEFT_SLASH) + DOC_HTML);
		}
		if (Boolean.TRUE.equals(env.getProperty(DRUID_SWITCH_ENABLE, boolean.class))) {
			System.out.println("Druid连接池监控已开启,请务必设置复杂账号密码:");
			System.out.println(contextPath + env.getProperty(DRUID_URL_PATTERN));
		}
		System.out.println("------------------------------------------------\n");
	}

}